package com.augurit.gzcgwsp.rqqyjyxk.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.Struts2Utils;

import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.base.action.ExtCrudActionSupport;
import com.augurit.common.util.ExtUtils;
import com.augurit.common.util.lang.DateUtils;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkPzrqgyzdjb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqjszdjb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqjszrypbqk;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqjszzysb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRypbqk;
import com.augurit.gzcgwsp.excelimportexport.service.IYwRqQyjyxkPzrqgyzdjbService;
import com.augurit.gzcgwsp.excelimportexport.service.IYwRqQyjyxkRqjszdjbService;
import com.augurit.gzcgwsp.excelimportexport.service.IYwRqQyjyxkRqjszrypbqkService;
import com.augurit.gzcgwsp.excelimportexport.service.IYwRqQyjyxkRqjszzysbService;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalPzrqgyzdjb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqjszdjb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqjszrypbqk;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqjszzysb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRypbqk;
import com.augurit.gzcgwsp.rqqyjyxk.service.IYwRqQyjyxkFinalPzrqgyzdjbService;
import com.augurit.gzcgwsp.rqqyjyxk.service.IYwRqQyjyxkFinalRqjszdjbService;
import com.augurit.wf.common.constant.WfConstant;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "yw-rq-qyjyxkgd.action", type = "redirect"),
	@Result(name = CrudActionSupport.SUCCESS, location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/YwRqQyjyxkgd.jsp"),
	@Result(name = CrudActionSupport.INPUT, location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/YwRqQyjyxkgd-input.jsp"),
	@Result(name = WfConstant.PRINT, location = WfConstant.PRINT_JSP),
	@Result(name = WfConstant.PRINT_DIR, location = WfConstant.PRINT_DIR_JSP),
	@Result(name = WfConstant.MAKE_DOCUMENT, location = "/gzcgwsp/wfex/client/common/make-document.jsp"),
	@Result(name = "showszdjb", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/YwRqQyjyxk-viewZdInfo.jsp"),
	@Result(name = "showoldszdjb", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/YwRqQyjyxk-viewOldZdInfo.jsp"),
	@Result(name = "toUpdate", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/YwRqQyss-toUpdate.jsp"),
	@Result(name = "showrqdjz", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/YwRqQyjyxk-viewRqdjzInfo.jsp"),
	@Result(name = "showOldRqdjz", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/YwRqQyjyxk-viewRqdjzInfo.jsp"),
	
	@Result(name = "toclsb", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/otherInfo/clsbInfo.jsp")
	
})
public class YwRqQyjyxkQxssAction   extends ExtCrudActionSupport{
	
    @Autowired
    private IYwRqQyjyxkRqjszdjbService ywRqQyjyxkRqjszdjbService;
    @Autowired
    private IYwRqQyjyxkFinalRqjszdjbService rqjszdjbService;
    @Autowired
    private IYwRqQyjyxkRqjszrypbqkService ywRqQyjyxkRqjszrypbqkService;
    @Autowired
    private IYwRqQyjyxkRqjszzysbService ywRqQyjyxkRqjszzysbService;
    @Autowired
    private IYwRqQyjyxkPzrqgyzdjbService ywRqQyjyxkPzrqgyzdjbService;
    @Autowired
    private IYwRqQyjyxkFinalPzrqgyzdjbService pzrqgyService;
	private Page page = new Page(10);
    public String doUpdate(){
        return null;
    }
    
    /**
     * 燃气接收站、储配站、汽车加气站详情
     * @return
     */
    public String showzdInfo(){
        String zdid=getRequest().getParameter("zdid");
        YwRqQyjyxkRqjszdjb rqjszdjb=ywRqQyjyxkRqjszdjbService.getZdInfo(zdid);
        getRequest().setAttribute("rqjszdjb",rqjszdjb);
        
        return "showszdjb";
    }
    
    
    /**
     * 原来燃气接收站、储配站、汽车加气站详情
     * @return
     */
    public String showOldzdInfo(){
        String zdid=getRequest().getParameter("zdid");
        YwRqQyjyxkFinalRqjszdjb rqjszdjb=rqjszdjbService.getZdInfo(zdid);
        getRequest().setAttribute("rqjszdjb",rqjszdjb);
        return "showoldszdjb";
    }
    
    /**
     * 查人员
     * @return
     */
    public String getPersonData(){
    	  String zdid=getRequest().getParameter("zdid");
    	  String type=getRequest().getParameter("type");
  	    if(page==null){
	  		  page = new Page(10);
	  	 }
	    ExtUtils.initPageFromExtGridParam(getRequest(), page);
	    if("oldperson".equals(type)){
	    	 if(StringUtils.isNotBlank(zdid)){
		    	 page=rqjszdjbService.getPage(page,zdid,null,type);
		    	 for(int i=0;i<page.getResult().size();i++){
		    		 YwRqQyjyxkFinalRqjszrypbqk person=(YwRqQyjyxkFinalRqjszrypbqk) page.getResult().get(i);
		    		 if(StringUtils.isNotBlank(person.getNl()) && person.getNl().indexOf(".")>0){
		    			 person.setNl(person.getNl().substring(0,person.getNl().indexOf(".")));
		    		 }
		    		 
		    	 }
		    	 renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
		     }
	    }else{
		    if(StringUtils.isNotBlank(zdid)){
		    	 page=rqjszdjbService.getPage(page,zdid,null,"");
		    	 for(int i=0;i<page.getResult().size();i++){
		    		 YwRqQyjyxkRqjszrypbqk person=(YwRqQyjyxkRqjszrypbqk) page.getResult().get(i);
		    		 if(StringUtils.isNotBlank(person.getNl()) && person.getNl().indexOf(".")>0){
		    			 person.setNl(person.getNl().substring(0,person.getNl().indexOf(".")));
		    		 }
		    		 
		    	 }
		    	 renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
		     }
	    }
          return null;
    }
    
    
    /**
     * 查设备
     * @return
     */
    public String getZysbData(){
    	  String zdid=getRequest().getParameter("zdid");
    	  String type=getRequest().getParameter("type");
  	    if(page==null){
	  		  page = new Page(10);
	  	 }
	    ExtUtils.initPageFromExtGridParam(getRequest(), page);
	    if("oldsb".equals(type)){
	    	 if(StringUtils.isNotBlank(zdid)){
		    	 page=rqjszdjbService.getPage(page,zdid,null,type);
		    	 renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
		    }
	    }else{	 
	    	if(StringUtils.isNotBlank(zdid)){
	    	 page=rqjszdjbService.getPage(page,zdid,null,"sb");
	    	 renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
	      }
	    }
	  
          return null;
    }
    
    /**
     * 燃气站详情
     * @return
     */
    public String showrqzdInfo(){
        String zdid=getRequest().getParameter("zdid");
        //燃气站
        YwRqQyjyxkPzrqgyzdjb rqjszdjb=ywRqQyjyxkPzrqgyzdjbService.getZdInfo(zdid);
        //人员
        List<YwRqQyjyxkRypbqk> zysbs=ywRqQyjyxkPzrqgyzdjbService.getRyDatas("",rqjszdjb.getId());
        getRequest().setAttribute("rqdjz",rqjszdjb);
        getRequest().setAttribute("rqdjzrys",zysbs);
        return "showrqdjz";
    }
    
    
    /**
     * 原来燃气站详情
     * @return
     */
    public String showOldrqzdInfo(){
        String zdid=getRequest().getParameter("zdid");
        YwRqQyjyxkFinalPzrqgyzdjb rqjszdjb=pzrqgyService.getZdInfo(zdid);
        //人员
        List<YwRqQyjyxkFinalRypbqk> zysbs=pzrqgyService.getDatasByzdid(rqjszdjb.getId());
        getRequest().setAttribute("rqdjz",rqjszdjb);
        getRequest().setAttribute("rqdjzrys",zysbs);
        return "showOldRqdjz";
    }
    
    /**
     * 到材料申报页面
     * @return
     */
    public String toclsb(){
    	 String acceptNo=getRequest().getParameter("acceptNo");
    	 String qyid=getRequest().getParameter("qyid");
         getRequest().setAttribute("acceptNo",acceptNo);
         getRequest().setAttribute("qyid",qyid);
         return "toclsb";
    }
    
    /**
     * 获取材料申报的数据
     * @return
     */
    public String getClsbDatas(){
    	 String acceptNo=getRequest().getParameter("acceptNo");
    	 String qyid=getRequest().getParameter("qyid");
    	 String type=getRequest().getParameter("type");
    	    if(page==null){
  	  		  page = new Page(20);
  	  	 }
    	    
  	    ExtUtils.initPageFromExtGridParam(getRequest(), page);
  	    if(StringUtils.isNotBlank(acceptNo)){
  	    	 page=pzrqgyService.getClsbPage(acceptNo,page,null,"");
  	    	 renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
  	    }
  	    if(StringUtils.isNotBlank(qyid)){
  	    	 page=pzrqgyService.getClsbPage("",page,Long.valueOf(qyid),type);
  	    	renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
  	    }
    	 
    	return null;
    }

    /**
     * 取得HttpRequest的简化方法.
     */
    public static HttpServletRequest getRequest() {
        return ServletActionContext.getRequest();
    }
    
    
    public Object getModel() {
        return null;
    }

	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String list() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	
}
